package com.wf.quartz;

import com.wf.domain.User;
import com.wf.service.PaymentManageService;
import com.wf.service.SendMailService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

/**
 * @author mpk
 * @since 2024/9/10 19:41:24
 */
@Component
@Slf4j

public class EmailQuartz extends QuartzJobBean {

    @Autowired
    SendMailService sendMailService;
    @Autowired
    PaymentManageService paymentManageService;

    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        HashMap<User, List<String>> reminders = paymentManageService.reminders();
        Set<User> users = reminders.keySet();
        Iterator<User> iterator = users.iterator();
        while (iterator.hasNext()){
            User next = iterator.next();
            sendMailService.sendRemindersEmail(next.getEmail(), reminders.get(next).toString());
            log.info("成功向"+next.getEmail()+"发送账单信息");
        }
    }
}
